package com.txooo.library.utils;

import android.text.TextUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin on 2017/9/6.
 */

public class SplitStrToList {


    /**
     * 将一个list集合的url组合成带有逗号分隔的String
     */
    public static String splitListToString(List<String> urlList) {
        if (urlList == null) return null;
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < urlList.size(); i++) {
            if (i != urlList.size() - 1)
                sb.append(urlList.get(i)).append(",");
            else
                sb.append(urlList.get(i));
        }
        return sb.toString();
    }


    /**
     * 将一个url的字符串拆分成List集合返回
     **/
    public static List<String> splistStringToList(String urlString) {
        if (TextUtils.isEmpty(urlString))
            return null;
        List<String> urlList = new ArrayList<String>();
        if (urlString.contains(",")) {
            String[] strArray = urlString.split(",");
            for (String s : strArray)
                if (!TextUtils.isEmpty(s)) urlList.add(s);
        } else
            urlList.add(urlString);
        return urlList;

    }

    /**
     * 将一个url的字符串拆分成List集合返回
     **/
    public static List<String> splistStringToList(String urlString,String splitInfo) {
        if (TextUtils.isEmpty(urlString))
            return null;
        List<String> urlList = new ArrayList<String>();
        if (urlString.contains(splitInfo)) {
            String[] strArray = urlString.split(splitInfo);
            for (String s : strArray)
                if (!TextUtils.isEmpty(s)) urlList.add(s);
        } else
            urlList.add(urlString);
        return urlList;

    }
}
